#light
#r "office"
#r "Microsoft.Office.Interop.Word"
//#I "C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12"
open System
open System.Diagnostics
open System.IO
open System.Reflection
open Microsoft.Office.Interop.Word
open System.Collections.Generic

//Sub ExtractComments()
//Dim DocA As Document
//Dim DocB As Document
//Dim comm As Variant
//Dim Count As Long
//Dim sComment As String
//Set DocA = ActiveDocument
//Set DocB = Word.Documents.Add
//Count = 1
//For Each comm In DocA.Comments
//sComment = DocA.Comments(Count).Range.Text
//sComment = "(" & DocA.Comments(Count).Initial & Count & ") " & sComment
//DocB.Activate
//Selection.TypeText sComment & vbCr
//Count = Count + 1
//Next comm
//End Sub

let copyComments source target =
    let app = new ApplicationClass()
    
    let dir = Path.GetDirectoryName(target)
    let newTarget = Path.GetFileNameWithoutExtension(target) + "_new.doc"
    let newTarget = Path.Combine(dir, newTarget)
    
    File.Copy(target, newTarget, true)
    
    let docTaget = app.Documents.Open(ref (newTarget :> obj))
    let docSource = app.Documents.Open(ref (source :> obj))
    
    use docTagetCloser = 
        { new IDisposable with 
            Dispose() = 
                docTaget.TrackRevisions <- true
                docTaget.ShowRevisions <- true
                docTaget.Save()
                docTaget.Close() }
    use docTagetCloser = 
        { new IDisposable with 
            Dispose() = docSource.Close() }

    for comment in docSource.Comments do
        let text = comment.Range.Text
        printfn "text: %s - %s" comment.Scope.ID comment.Scope.Paragraphs.
        //let newComment = docTaget.Comments.Add()
        ()

copyComments 
    @"C:\Users\robert\Documents\Books\Foundations of F#_2\23894ch04_toAR.doc"
    @"C:\Users\robert\Documents\Books\Foundations of F#_2\7575ch04_fd.doc"
